package cn.com.scitc.licenseplateback.dao;

import cn.com.scitc.licenseplateback.model.NationalTreasuryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface NationalTreasuryDao extends JpaRepository<NationalTreasuryEntity, Integer> {

    /**
     * 测试时向数据库中添加成都、广元、宜宾相关立方库信息
     * @param city 城市代码
     * @param cln 立方库编号
     * @param cla 立方库地址
     */
    @Modifying
    @Transactional
    @Query(value="insert into NationalTreasury (CityCode,CubeLibraryNumber,CubeLibraryAddress) values (:city, :cln, :cla)", nativeQuery = true)
    void addRollCall(String city, String cln, String cla);

    /**
     * 查询当前城市的所有立方库信息列表
     * @param citycode
     * @return
     */
    @Query(value = "select n from NationalTreasuryEntity n where n.cityCode = :citycode")
    List<NationalTreasuryEntity> findAllByCurrentPosCube(int citycode);


    /**
     * 查询当前城市的所有立方库信息列表 - 分页查询
     * @param citycode
     * @return
     */
    @Query(value = "select * from NationalTreasury where CityCode = :citycode limit :start, :len ",nativeQuery = true)
    List<NationalTreasuryEntity> findByCurrentLimitCube(String citycode, int start, int len);

    /**
     * 根据详细的立方库编号进行定位查询
     * @param cubeLibraryNumber 立方库编号 (75-0)
     * @return
     */
    @Query(value = "select n from NationalTreasuryEntity  n where n.cubeLibraryNumber = :cubeLibraryNumber")
    NationalTreasuryEntity findByCubeLibraryNumber(String cubeLibraryNumber);
}
